﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="pragma" content="no-cache" />
    <meta http-equiv="Cache-Control" content="no-cache, must-revalidate" />
    <meta http-equiv="expires" content="0" />
    <title>FaceCat-Html5</title>
</head>
<body>
    <canvas id="tabCanvas" width="500" height="300" style="position: fixed; left: 0px; top: 0px;"/>
    <script type="text/javascript" src="facecat.js"></script>
    <script type="text/javascript">
        let canvasTab = document.getElementById("tabCanvas"); //绘图区域
        canvasTab.width = window.innerWidth;
        canvasTab.height = window.innerHeight;
        let paintTab = new FCPaint(); //绘图对象
        paintTab.canvas = canvasTab;
        scaleCanvas(paintTab);
        //判断主题色
        paintTab.defaultUIStyle = "dark";
        let url = location.href;
        if (url.indexOf("color=light") != -1) {
            paintTab.defaultUIStyle = "light";
        }
        //判断移动端
        paintTab.isMobile = isMobileMode();
        if (paintTab.isMobile) {
            paintTab.scaleFactorX = 2.5;
            paintTab.scaleFactorY = 2.5;
        }

        //创建多页夹
        let tabView = new FCTabView();

        //初始化多页夹
        let initTab = function () {
            tabView.dock = "fill";
            addView(tabView, paintTab);
            if (tabView.paint.defaultUIStyle == "dark") {
                tabView.backColor = "rgb(0,0,0)";
                tabView.borderColor = "rgb(100,100,100)";
                tabView.textColor = "rgb(255,255,255)";
            } else if (tabView.paint.defaultUIStyle == "light") {
                tabView.backColor = "rgb(255,255,255)";
                tabView.borderColor = "rgb(150,150,150)";
                tabView.textColor = "rgb(0,0,0)";
            }
            tabView.borderColor = null;
            tabView.underLineColor = "rgb(255,215,0)";
            tabView.underLineSize = 5;
            tabView.layout = "bottom";
            tabView.useAnimation = true;

            for (let i = 0; i < 4; i++) {
                let tabPage = new FCTabPage();
                if (i == 0) {
                    tabPage.visible = true;
                } else {
                    tabPage.visible = false;
                }
                tabPage.size = new FCSize(100, 100);
                tabPage.location = new FCPoint(0, 0);
                tabPage.borderColor = null;
                tabPage.parent = tabView;
                let tabButton = new FCView();
                tabPage.paint = paintTab;
                tabButton.viewType = "tabbutton";
                tabButton.text = "第" + (i + 1) + "页";
                tabButton.visible = true;
                tabButton.size = new FCSize(100, 40);
                tabButton.location = new FCPoint(0, 0);
                tabButton.textColor = "rgb(0,0,0)";
                if (i == 0) {
                    tabPage.backColor = "rgb(255,0,0)";
                } else if (i == 1) {
                    tabPage.backColor = "rgb(0,255,0)";
                } else if (i == 2) {
                    tabPage.backColor = "rgb(0,0,255)";
                }
                else if (i == 3) {
                    tabPage.backColor = "rgb(255,0,255)";
                }
                addTabPage(tabView, tabPage, tabButton);
                if (tabView.paint.defaultUIStyle == "dark") {
                    tabButton.backColor = "rgb(0,0,0)";
                    tabButton.borderColor = "rgb(100,100,100)";
                    tabButton.textColor = "rgb(255,255,255)";
                } else if (tabView.paint.defaultUIStyle == "light") {
                    tabButton.backColor = "rgb(255,255,255)";
                    tabButton.borderColor = "rgb(150,150,150)";
                    tabButton.textColor = "rgb(0,0,0)";
                }
                tabButton.font = "Default,12";
            }
        }
        initTab();
        updateTabLayout(tabView);

        /*
        * 点击方法
        * view:视图
        * firstTouch:是否第一次触摸
        * firstPoint:第一次触摸的坐标
        * secondTouch:是否第二次触摸
        * secondPoint:第二次触摸的坐标
        * clicks:点击次数
        */
        let onClick_Tab = function (view, firstTouch, firstPoint, secondTouch, secondPoint, clicks) {
            onClickDefault(view, firstTouch, firstPoint, secondTouch, secondPoint, clicks);
        };

        /*
        * 鼠标按下实现方法
        * view:视图
        * mp:坐标
        * button:按钮
        * clicks:点击次数
        * delta:滚轮值
        */
        let onMouseDown_Tab = function (view, mp, buttons, clicks, delta) {
            onMouseDownDefault(view, mp, buttons, clicks, delta);
        };

        /*
        * 鼠标滚动实现方法
        * view:视图
        * mp:坐标
        * button:按钮
        * clicks:点击次数
        * delta:滚轮值
        */
        let onMouseWheel_Tab = function (view, mp, buttons, clicks, delta) {
            if (window.event.ctrlKey && view.paint) {
                //放大显示
                if (delta < 0) {
                    view.paint.scaleFactorX = view.paint.scaleFactorX + 0.1;
                    view.paint.scaleFactorY = view.paint.scaleFactorY + 0.1;
                    resizeAll();
                    //缩小显示
                } else if (delta > 0) {
                    if (view.paint.scaleFactorX > 0.2) {
                        view.paint.scaleFactorX = view.paint.scaleFactorX - 0.1;
                        view.paint.scaleFactorY = view.paint.scaleFactorY - 0.1;
                        resizeAll();
                    }
                }
                return;
            }
            onMouseWheelDefault(view, mp, buttons, clicks, delta);
        };

        /*
        * 触摸开始方法
        * view:视图
        * firstTouch:是否第一次触摸
        * firstPoint:第一次触摸的坐标
        * secondTouch:是否第二次触摸
        * secondPoint:第二次触摸的坐标
        */
        let onTouchBegin_Tab = function (view, firstTouch, firstPoint, secondTouch, secondPoint) {
            onTouchBeginDefault(view, firstTouch, firstPoint, secondTouch, secondPoint);
        };

        /*
        * 触摸移动方法
        * view:视图
        * firstTouch:是否第一次触摸
        * firstPoint:第一次触摸的坐标
        * secondTouch:是否第二次触摸
        * secondPoint:第二次触摸的坐标
        */
        let onTouchMove_Tab = function (view, firstTouch, firstPoint, secondTouch, secondPoint) {
            onTouchMoveDefault(view, firstTouch, firstPoint, secondTouch, secondPoint);
        };

        /*
        * 触摸结束方法
        * view:视图
        * firstTouch:是否第一次触摸
        * firstPoint:第一次触摸的坐标
        * secondTouch:是否第二次触摸
        * secondPoint:第二次触摸的坐标
        */
        let onTouchEnd_Tab = function (view, firstTouch, firstPoint, secondTouch, secondPoint) {
            onTouchEndDefault(view, firstTouch, firstPoint, secondTouch, secondPoint);
        };

        /*
        * 鼠标移动实现方法
        * view:视图
        * mp:坐标
        * button:按钮
        * clicks:点击次数
        * delta:滚轮值
        */
        let onMouseMove_Tab = function (view, mp, buttons, clicks, delta) {
            onMouseMoveDefault(view, mp, buttons, clicks, delta);
        };

        /*
        * 鼠标抬起实现方法
        * view:视图
        * mp:坐标
        * button:按钮
        * clicks:点击次数
        * delta:滚轮值
        */
        let onMouseUp_Tab = function (view, mp, buttons, clicks, delta) {
            onMouseUpDefault(view, mp, buttons, clicks, delta);
        };

        /*
        * 重绘背景的实现方法
        * view:视图
        * paint:绘图对象
        * clipRect:裁剪区域
        */
        paintTab.onPaint = function (view, paint, clipRect) {
            onPaintDefault(view, paint, clipRect);
        };

        /*
        * 重绘边框的实现方法
        * view:视图
        * paint:绘图对象
        * clipRect:裁剪区域
        */
        paintTab.onPaintBorder = function (view, paint, clipRect) {
            onPaintBorderDefault(view, paint, clipRect);
        };

        /*
        * 更新布局的实现方法
        * views:视图集合
         */
        paintTab.onUpdateView = function (views) {
            updateViewDefault(views);
        }

        //注册事件
        addMouseDownEvent(canvasTab, paintTab, onMouseDown_Tab);
        addMouseMoveEvent(canvasTab, paintTab, onMouseMove_Tab);
        addMouseWheelEvent(canvasTab, paintTab, onMouseWheel_Tab);
        addMouseUpEvent(canvasTab, paintTab, onMouseUp_Tab, onClick_Tab);
        addTouchBeginEvent(canvasTab, paintTab, onTouchBegin_Tab);
        addTouchMoveEvent(canvasTab, paintTab, onTouchMove_Tab);
        addTouchEndEvent(canvasTab, paintTab, onTouchEnd_Tab, onClick_Tab);

        /*
         * 重置大小
         */
        let resizeAll = function () {
            canvasTab.width = document.documentElement.clientWidth;
            canvasTab.height = document.documentElement.clientHeight;
            scaleCanvas(paintTab);
            updateViewDefault(paintTab.views);
            invalidate(paintTab);
        };

        /*
        * 监听大小改变
        */
        window.onresize = function () {
            resizeAll();
        };

        /*
        * 旋转监听
        */
        window.onorientationchange = function () {
            resizeAll();
        };
        updateViewDefault(paintTab.views);
        //刷新界面
        invalidate(paintTab);
    </script>
</body>
</html>
